package com.centaline.androidsalesblog.adapter.viewholder;

import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.baidu.mapapi.model.LatLng;
import com.bumptech.glide.DrawableRequestBuilder;
import com.centaline.androidsalesblog.R;
import com.centaline.androidsalesblog.model.databaseobject.PostDo;
import com.centaline.androidsalesblog.utils.CentaDistanceUtil;
import com.centaline.androidsalesblog.utils.PriceUtil;
import com.centaline.androidsalesblog.widgets.CustomListTagView;
import com.centanet.framework.glide.GlideLoad;

import java.util.Locale;

/**
 * 二手列表
 * Created by guilin on 16/1/26.
 */
public class EsfNewsVH extends RecyclerView.ViewHolder {

    public ImageView img_logo;
    public AppCompatTextView atv_title, atv_tag_fir, atv_tag_sec, atv_price,atv_status;
    public CustomListTagView customListTagView;

    public EsfNewsVH(View itemView) {
        super(itemView);
        img_logo = (ImageView) itemView.findViewById(R.id.img_logo);
        atv_title = (AppCompatTextView) itemView.findViewById(R.id.atv_title);
        atv_tag_fir = (AppCompatTextView) itemView.findViewById(R.id.atv_tag_fir);
        atv_tag_sec = (AppCompatTextView) itemView.findViewById(R.id.atv_tag_sec);
        atv_price = (AppCompatTextView) itemView.findViewById(R.id.atv_price);
        atv_status = (AppCompatTextView) itemView.findViewById(R.id.atv_status);
        customListTagView = (CustomListTagView) itemView.findViewById(R.id.customListTagView);
    }

    public void load(DrawableRequestBuilder<String> requestBuilder, int viewType, PostDo postDo, LatLng location) {
        GlideLoad.load(new GlideLoad.Builder(requestBuilder, postDo.getThumbPath())
                .placeHolder(R.drawable.ic_centa_square_logo)
                .error(R.drawable.ic_centa_square_logo)
                .openWifiSwitch()
                .into(img_logo));
        atv_title.setText(postDo.getTitle());
        atv_tag_fir.setText(String.format(Locale.CHINA, "%d室%d厅  %.2f平  %s",
                postDo.getBedroomCount(),
                postDo.getSittingRoomCount(),
                postDo.getSize(),
                postDo.getDirection()));
        switch (viewType) {
            case 1:
                atv_tag_sec.setText(CentaDistanceUtil.distanceOfPostAndMetro(postDo.getRailLineNames(),
                        postDo.getRailWayName(),
                        postDo.getRailWayDistance()));
                break;
            default:
                atv_tag_sec.setText(postDo.getCnEstate());
                break;
        }
        atv_price.setText(PriceUtil.salePrice(postDo.getPrice()));
        customListTagView.setTags(postDo.getKeyWords());
    }
}
